﻿@{
    Layout = "~/Views/Shared/_PopupLayout.cshtml";
}

@model LineOfBusiness.Poco.AD_tblUserAccount

@Html.LOBHtmlHelper().Busy("pupopBusy")
@{Html.LOBHtmlHelper().tdLable("120");}

<style>
 fieldset { 
    margin: 8px;
    border: 1px solid silver;
    padding: 8px;    
    border-radius: 4px;
}
legend{
    padding: 2px;        
}
</style>
 

    <form id="frm">
        <table style="width:100%;padding-left:15px;padding-right:15px">
            <tr>
                <td class="tdLabel">
                    @Html.LOBHtmlHelper().Label("lblUserID", "User ID")
                </td>
                <td >
                    @Html.LOBHtmlHelper().InputFor("UserGroupID", InputType.Text, "40")
                </td>
            </tr>
        
            <tr>
                <td class="tdLabel">
                    @Html.LOBHtmlHelper().Label("lblUserName", "User Name")
                    
                </td>
                <td>
                    @Html.LOBHtmlHelper().InputFor("UserGroupName", InputType.Text,1 )
                
                </td>
            </tr>

            <tr>
                 <td class="tdLabel">
                    @Html.LOBHtmlHelper().Label("lblDescription", "Description")
                    
                </td>
                <td>
                    @Html.LOBHtmlHelper().InputFor("Description", InputType.Text,1 )
                
                </td>
            </tr>
            <tr>
                <td >
                    @Html.LOBHtmlHelper().Label("lblPassword", "Password")
                </td>
                <td>
                    @Html.LOBHtmlHelper().InputFor("Password", InputType.Password, 0, new { @class = "k-textbox" })
                </td>
            </tr>

            <tr>
                <td >
                    @Html.LOBHtmlHelper().Label("lblConfirmPassword", "Confirm Password")
                </td>
                <td>
                    @Html.LOBHtmlHelper().Input("ConfirmPassword", InputType.Password, 0, @Model.Password, new { @class = "k-textbox", style="width:100%" })
                </td>
            </tr>

            <tr>
                <td></td>
                <td>
                    @Html.LOBHtmlHelper().CheckBoxFor(t=>t.FAdm) 
                    @Html.LOBHtmlHelper().Label("lblAdmin", "Is Admin")
                </td>
                
            </tr>

            <tr>
                <td></td>
                <td>
                    @Html.LOBHtmlHelper().CheckBoxFor(t=>t.FValid) 
                    @Html.LOBHtmlHelper().Label("lblActive", "Is Active")
                </td>
                
            </tr>


            <tr>
                <td></td>
                <td>
                    @Html.LOBHtmlHelper().CheckBoxFor(t=>t.CantChangePwd) 
                    @Html.LOBHtmlHelper().Label("lblCantChangePass", "User can not change password")
                </td>
                
            </tr>

             <tr>
                 <td></td>
                <td>
                    @Html.LOBHtmlHelper().CheckBoxFor(t=>t.PwdNeverExpire) 
                    @Html.LOBHtmlHelper().Label("lblPwdNeverExpire", "Password never expire")
                </td>
                
            </tr>

             <tr>
                 <td></td>
                <td >
                    @Html.LOBHtmlHelper().CheckBoxFor(t=>t.MustChangePwd) 
                    @Html.LOBHtmlHelper().Label("lblMustChangePwd", "User can change password in first login")
                </td>
                
            </tr>

              <tr>
                 <td class="tdLabel" style="vertical-align:top">
                     <div style="height:5px"></div>
                    @Html.LOBHtmlHelper().Label("lblGroup", "Group", new { style="margin-top:5px"})
                    
                </td>
                <td>
                     <table cellpadding="1" cellspacing="1" style="table-layout:fixed;width:100%">
                 <tr>
                     <td>
                         @Html.LOBHtmlHelper().GridView("grvtblUserGroup","tblUserGroup","AD_tblUserGroup",true,false,new { @style = "width: 100%;height:150px"},"UserID",@Model.UserGroupID,false,false,"",true,true)  
                     </td>
                 </tr>
             </table>
                </td>
            </tr>
        </table>

        <div id="_blank" style="height:0px">
        </div>
    </form>

<div class="Line"></div>

<div  style="text-align:right">
    <div class="buttons">
        @if(ViewBag.Edit!=-1)
        {
            <button id="btnSave" class="positive" onclick= "SavePopup()">
                <img src="@Html.BaseUrl()Content/images/toolbar/save.png" alt="" /> 
                @Html.LOBHtmlHelper().C("Save") 
            </button> 
        }
        <button class="positive" onclick= "Close()">
            <img src="@Html.BaseUrl()Content/images/toolbar/close.png" alt="" /> 
            @Html.LOBHtmlHelper().C("Close")
        </button> 
    </div>
</div>

<script type="text/javascript">

    var codeBasePopup = new CodeBasePopup();

    $(document).ready(function () {

        codeBasePopup.init('@ViewBag.Edit', "UserGroupID", "@Url.Action("Save","UserAccount")", '@Model.UserGroupID', "grvtblUserGroup", -1, -1);

        codeBasePopup.SetEntityDetail('AD_tblUserGroup');


        setTimeout(function () { $("#UserGroupID").focus(); }, 500);

        SetHeightGrid('grvtblUserGroup', 150);
        
       
    });

    $(window).load(function () {
        
        var gridview = $("#grvtblUserGroup").data("kendoGrid");
        gridview.hideColumn("UserID")
        gridview.showColumn("GroupID")
        gridview.hideColumn("UserName")
        gridview.showColumn("GroupName")
    });

    function SavePopup() {
        if ($("#ConfirmPassword").val() != $("#Password").val())
        {
            ShowMessageError("PwNotSame", "Please enter right confirm password")
            return;
        }
        codeBasePopup.SavePopup();
    }

    function Add_record() {
        var gridview = $("#grvtblUserGroup").data("kendoGrid");

        gridview.addRow();

        var rows = gridview.dataSource.data();

        rows[rows.length - 1].set("UserID", $('#UserGroupID').val());
    }


    function Delete_record() {
        codeBasePopup.Delete_record();
    }

    function Close() {
        codeBasePopup.Close();
    }

    function onGridEdit(e, propertyEdit) {
        if (propertyEdit == "GroupID") {
            codeBasePopup.SetMultiPredicateComplexForCombo("GroupID", "FGroup.Equals(~0)", "true");
        }

        if (propertyEdit == "UserID") {
            codeBasePopup.SetMultiPredicateComplexForCombo("UserID", "FGroup.Equals(~0)", "false");
        }

        if (propertyEdit == "GroupName") {
            codeBasePopup.SetMultiPredicateComplexForCombo("GroupName", "FGroup.Equals(~0)", "true");
        }

        if (propertyEdit == "UserName") {
            codeBasePopup.SetMultiPredicateComplexForCombo("UserName", "FGroup.Equals(~0)", "false");
        }
    }

    function onPropertyChanged(name, old, value) {
        switch (name) {
            case "GroupID":
                var model = GetCurrentModelCombo("GroupID");
                if (typeof model != 'undefined') {
                    SetValueForGrid("grvtblUserGroup", "GroupName", model.UserGroupName);
                }

                break;
            case "GroupName":
                var model = GetCurrentModelCombo("GroupName");
                if (typeof model != 'undefined') {
                    SetValueForGrid("grvtblUserGroup", "GroupID", model.UserGroupID);
                }
                break;
            default:
                break;
        }
    }
</script>